package com.treetao.union.db;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.treetao.union.db.model.CommonSetting;
import com.treetao.union.db.pojo.SettingTypeOrder;
import com.treetao.union.db.pojo.SettingTypeSystem;
import com.treetao.union.db.pojo.SettingTypeWeixin;
import com.treetao.union.db.service.CommonSettingService;

@Component
public class SettingConvertService {
	@Autowired
	private CommonSettingService settingService;
	
	public SettingTypeSystem getSystemSetting() {
		CommonSetting cs = settingService.getCommonSetting(Const.SettingType.SYSTEM);
		if(cs!=null) {
			return JSONObject.parseObject(cs.getJson(), SettingTypeSystem.class);
		}
		return null;
	}
	
	public SettingTypeWeixin getWeixinSetting() {
		CommonSetting cs = settingService.getCommonSetting(Const.SettingType.WEIXIN);
		if(cs!=null) {
			return JSONObject.parseObject(cs.getJson(), SettingTypeWeixin.class);
		}
		return null;
	}
	
	public SettingTypeOrder getOrderSetting() {
		CommonSetting cs = settingService.getCommonSetting(Const.SettingType.ORDER);
		if(cs!=null) {
			return JSONObject.parseObject(cs.getJson(), SettingTypeOrder.class);
		}
		return null;
	}
}
